import java.util.LinkedList;
import java.util.Queue;

public class Ygj {
    public static void main(final String[] args) {
        lastPeople(10, 3);

    }

    private static void lastPeople(int total, int k) {
        //初始化人数，人数排号从1开始；
        Queue<Integer> queue = new LinkedList<>();
        for (int index = 1; index <= total; index++) {
            queue.add(index);
        }
        System.out.println("初始队列：" + queue);
        while (queue.size() > 1) {
            for (int index = 1; index <= k; index++) {
                Integer current = queue.poll();
                if (index == k) {
                    System.out.println(String.format("出局的人:%d", current));
                    System.out.println("剩余的人和顺序：" + queue);
                } else {
                    queue.add(current);
                }
            }
        }
        System.out.println("最终存活：" + queue);
    }
}